///<reference types="@i3yun/viewer" />
import { AppSetting } from '../AppSetting';
import { Container } from '../Container';
import { BaseGui } from "../Services/BaseGui";
import { ViewerService } from "../Services/ViewerService";

export class EEPToolGui extends BaseGui {
    title: string = `操控工具[${EEPToolGui.name}]`;
    AppSetting = Container.defineProperty(AppSetting);
    ViewerService = Container.defineProperty(ViewerService);
    eeptoolExt: any;
    async Init(): Promise<void> {

    }
    UpdateGui(): void {
        if (this.AppSetting.ViewerEnableGui == "1")
            return;
        let gui = this.gui;
        this.getEepTool();
        let fun = new DatguiEepTool(this);
        let updateGUI = () => {
            Array.from(gui.__controllers).forEach(_ => {
                gui.remove(_);
            })
            gui.add(fun, "选择");
            gui.add(fun, "平移");
            gui.add(fun, "旋转");
            gui.add(fun, "漫游");
            gui.add(fun, "环视");
            gui.add(fun, "缩放");
        }
        updateGUI();
    }
    //什么时候用什么时候加载
    async getEepTool() {
        let viewer: Sippreep.Viewing.Viewer3D & { baseRestoreState?: any } = await this.ViewerService.ViewerPromise;
        let temp: any = await viewer.loadExtension("Sippreep.Extensions.EEPTools.EEPToolExtension", {});
        if (!viewer.baseRestoreState) {
            viewer.baseRestoreState = viewer.restoreState;
            viewer.restoreState = function (v, f, i) {
                return viewer.baseRestoreState(v, f, true);
            };
        }
        return temp as Sippreep.Extensions.EEPTools.EEPToolExtension;
    }
}
class DatguiEepTool {
    constructor(private eeptoolGui: EEPToolGui) {

    }
    async 选择() {
        let tool = await this.eeptoolGui.getEepTool();
        tool.set3DCommand(Sippreep.Extensions.EEPTools.EEPToolCommand.SELECT);
    }
    async 平移() {
        let tool = await this.eeptoolGui.getEepTool();
        tool.set3DCommand(Sippreep.Extensions.EEPTools.EEPToolCommand.PAN);
    }
    async 旋转() {
        let tool = await this.eeptoolGui.getEepTool();
        tool.set3DCommand(Sippreep.Extensions.EEPTools.EEPToolCommand.ROTATE);
    }
    async 漫游() {
        let tool = await this.eeptoolGui.getEepTool();
        tool.set3DCommand(Sippreep.Extensions.EEPTools.EEPToolCommand.ROAM);
    }
    async 环视() {
        let tool = await this.eeptoolGui.getEepTool();
        tool.set3DCommand(Sippreep.Extensions.EEPTools.EEPToolCommand.LOOKAROUND);
    }
    async 缩放() {
        let tool = await this.eeptoolGui.getEepTool();
        tool.set3DCommand(Sippreep.Extensions.EEPTools.EEPToolCommand.ZOOM);
    }

}